<template>
  <div>
    <el-table :data="tableData" stripe border style="width: 100%">
      <el-table-column prop="createTime" label="创建时间" width="180"/>
      <el-table-column prop="taskName" label="任务名称" width="180"/>
      <el-table-column prop="address" label="申请人"/>
      <el-table-column label="操作">
        <el-button round type="primary" @click="look()">审核</el-button>
        <el-button round type="primary" @click="look3()">流程图</el-button>
      </el-table-column>
    </el-table>

    <el-dialog
        v-model="dialogVisible"
        title="查看"
        width="40%">
      <el-form>
        <el-form-item label="天数">
          <el-input v-model="day"></el-input>
        </el-form-item>
        <el-form-item label="请假原因">
          <el-input type="textarea" v-model="reason"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="look1()" type="success">同意</el-button>
          <el-button @click="look2()" type="danger">拒绝</el-button>
        </el-form-item>
      </el-form>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false" type="primary">关闭</el-button>
      </span>
      </template>
    </el-dialog>

    <el-dialog
        v-model="dialogImg"
        title="流程图"
        width="40%">
      <img :src="imgSrc">
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogImg = false" type="primary">关闭</el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>

export default {
  name: "ListName",
  data() {
    return {
      dialogVisible: false,
      dialogImg: false,
      tableData: [],
      reason: '',
      day: '',
      taskId: '',
      processId: '',
      imgSrc: '',
    }
  },
  mounted() {
    this.axios.get("http://172.20.10.3:8080/getNeedDoTasks?userId=1").then(res => {
      if (res.status === 200) {
        this.tableData = res.data
        this.taskId = res.data[0].taskId
        this.processId = res.data[0].processId
      }
    }).catch((err) => {
      console.log(err)
      this.$message({
        message: "网络错误",
        type: 'error',
      })
    })
  },
  methods: {
    look() {
      this.axios.get("http://172.20.10.3:8080/processVariables?taskId=" + this.taskId).then(res => {
        this.day = res.data.days;
        this.reason = res.data.reason;
      })
      this.dialogVisible = true

    },
    look1() {
      this.axios.get("http://172.20.10.3:8080/audit?taskId=" + this.taskId + "&result=" + "通过").then(res => {
        this.day = res.data.days;
        this.reason = res.data.reason;
        this.dialogVisible = false
      })
    },
    look2() {
      this.axios.get("http://172.20.10.3:8080/audit?taskId=" + this.taskId + "&result=" + "驳回").then(res => {
        this.day = res.data.days;
        this.reason = res.data.reason;
        this.dialogVisible = false
      })
    },
    look3() {
      this.dialogImg = true
      this.axios.get("http://172.20.10.3:8080/genProcessDiagrams?processId=" + this.processId).then(res => {
        this.imgSrc = 'data:image/png;base64,' + res.data
      })
    }
  }


}


</script>

<style scoped>
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
